#ifndef TIMER_SERVICE_HPP
#define TIMER_SERVICE_HPP

#include <functional>
#include <service/svc_manager.hpp>

class PI_API ITask
{
public:
    virtual ~ITask () = default;

    virtual ITask* cycle(u64 ms) = 0;

    virtual ITask* delay(u64 ms) = 0;

    virtual ITask* auto_remove(bool on = false) = 0;

    virtual void start() = 0;

    virtual void start_repeat(u32 times = ~0u) = 0;

    virtual void stop() = 0;

    virtual f64 timeout() const = 0;

    virtual void execute() = 0;

    virtual void remove() = 0;
};

class ITimerService : public TaggedService<service_type::timer> {
public:
    using proc = std::function<void()>;
protected:
    virtual PI_API ITask* create_scheduler_impl(proc proc) = 0;
public:
    PI_INLINE ITask* create_scheduler(proc p) {
        return create_scheduler_impl(std::move(p));
    }
};

#endif /* TIMER_SERVICE_HPP */
